//
//  HomeViewModel.m
//  MoXiProject
//
//  Created by 周筱雯 on 2017/7/17.
//  Copyright © 2017年 周筱雯. All rights reserved.
//

#import "HomeViewModel.h"

@implementation HomeViewModel
- (instancetype)init
{
    self = [super init];
    if (self) {
        
        self.bannerList = [[NSMutableArray alloc] initWithCapacity:0];
        self.homeArrayList = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return self;
}
/*
 首页bannner
 */
-(RACSignal *)mainBannerRequestpParameter:(NSString* )pageNo pageSize:(NSString* )pageSize{
    
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        
        NSDictionary *param = @{@"pageNo"  :pageNo,
                                @"pageSize":pageSize
                                };
        
        [ScyRequestOperationManager MainBannerParametersDic:param success:^(NSDictionary *result) {
            
            if (result) {
                
                self.bannerList =(NSMutableArray *)[MTLJSONAdapter modelsOfClass:[MainBannerModel class] fromJSONArray:result[@"result"] error:nil];
                
            }
            
            NSLog(@"首页Banner：%@",result);
            
            [subscriber sendNext:result];
            [subscriber sendCompleted];
            
        } failture:^(id result) {
            
            [self.bannerList removeAllObjects];
            [subscriber sendError:result];
            
        }];
        
        return nil;
    }];
}
/*
 首页新闻
 */
-(RACSignal *)mainNewsRequestpParameter:(NSString* )pageNo pageSize:(NSString* )pageSize typeId:(NSString* )typeId{
    
    
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        
        NSDictionary *param = @{@"pageNo"  :pageNo,
                                @"pageSize":pageSize,
                                @"typeId":typeId
                                };
        
        [ScyRequestOperationManager MainNewsParametersDic:param success:^(NSDictionary *result) {
            
            if (result) {
                
                
                
                self.homeArrayList =(NSMutableArray *)[MTLJSONAdapter modelsOfClass:[MainNewsModel class] fromJSONArray:result[@"result"] error:nil];
                
            }
            
                        NSLog(@"首页新闻：%@",result);
            
            [subscriber sendNext:result];
            [subscriber sendCompleted];
            
        } failture:^(id result) {
            
            [self.homeArrayList removeAllObjects];
            [subscriber sendError:result];
            
        }];
        
        return nil;
    }];
    
}
@end
